package com.ax.base.common.controller;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ax.base.common.domain.BaseDoctor;
import com.ax.base.common.domain.BasePharmacist;
import com.ax.base.common.domain.Tree;
import com.ax.base.common.service.DoctorPharmacistService;
import com.ax.base.common.utils.AjaxRes;
import com.ax.base.common.utils.Const;
import com.ax.base.system.domain.MenuDO;


@Controller
@RequestMapping("/sys/doctorPharmacist")
public class DoctorPharmacistSkipController {

	@Autowired
	DoctorPharmacistService doctorPharmacistService;
	/**
	 * 菜单页面的跳转
	 */
	@GetMapping("/pharmacist")
	String pharmacist(Model model) {
		return "org/pharmacist/pharmacist";
	}
	
	/**
	 * 查看药师详情(模块:药师，药师详情)
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return PageUtils
	 */
	@RequestMapping("/queryBasePharmacist")
	@ResponseBody
	public List<BasePharmacist> queryBasePharmacist(@RequestParam Map<String, Object> params){
	//	PageUtils basePharmacists = doctorPharmacistService.queryBasePharmacistSer(params);
		List<BasePharmacist> BasePharmacists = doctorPharmacistService.queryBasePharmacistSer(params);
		return BasePharmacists;
	}
	
	/**
	 * 查看药师详情(新增)
	 * 
	 * @param  无
	 *           
	 * @return SUCC
	 */
	@GetMapping("/add")
	String add(Model model) {
		return "org/pharmacist/add";
	}
	
	/**
	 * 查看药师详情(修改)
	 * 
	 * @param Long id
	 *           
	 * @return SUCC
	 */
	@GetMapping("/edit/{id}")
	String edit(Model model,@PathVariable("id") Long id) {
		model.addAttribute("pharmacist",doctorPharmacistService.getPharmacistSer(id));
		return "org/pharmacist/edit";
	}
	
	/**
	 * 新增药师详情(模块:药师)
	 * 
	 * @param Map<String,Object> map
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/insertBasePharmacist")
	@ResponseBody
	public AjaxRes insertBasePharmacist(AjaxRes ajaxRes,@RequestParam Map<String,Object> params,BasePharmacist basePharmacist){
		try {
			this.doctorPharmacistService.insertBasePharmacistSer(params,basePharmacist);
			ajaxRes.setSucceed(Const.SAVE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 修改药师详情(模块:药师)
	 * 
	 * @param Map<String,Object> map
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/updateBasePharmacist")
	@ResponseBody
	public AjaxRes updateBasePharmacist(AjaxRes ajaxRes,@RequestParam Map<String,Object> params){
		try {
			this.doctorPharmacistService.updateBasePharmacistSer(params);
			ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 菜单页面的跳转
	 */
	@GetMapping("/doctor")
	String doctor(Model model) {
		return "org/doctor/doctor";
	}
	
	/**
	 * 查看医生详情(模块:医生呈现，医生详情*查询某科室下面的医生)
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return PageUtils
	 */
	@RequestMapping("/queryBaseDoctor")
	@ResponseBody
	public List<BaseDoctor> queryBaseDoctor(@RequestParam Map<String, Object> params){
	//	PageUtils baseDoctors = doctorPharmacistService.queryBaseDoctorSer(params);
		List<BaseDoctor> baseDoctors = doctorPharmacistService.queryBaseDoctorSer(params);
	    return baseDoctors;
	}
	
	/**
	 * 查看医师详情(新增)
	 * 
	 * @param  无
	 *           
	 * @return SUCC
	 */
	@GetMapping("doctor/add")
	String doctorAdd(Model model) {
		return "org/doctor/add";
	}
	
	/**
	 * 新增医生详情(模块:医生)
	 * 
	 * @param BaseDoctor baseDoctor
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/insertBaseDoctor")
	@ResponseBody
	public AjaxRes insertBaseDoctor(AjaxRes ajaxRes,BaseDoctor baseDoctor){
		try {
			this.doctorPharmacistService.insertBaseDoctorSer(baseDoctor);
			ajaxRes.setSucceed(Const.SAVE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 查看医师详情(修改)
	 * 
	 * @param Long id
	 *           
	 * @return SUCC
	 */
	@GetMapping("doctor/edit/{id}")
	String doctoreEdit(Model model,@PathVariable("id") Long id) {
		model.addAttribute("doctor",doctorPharmacistService.getDoctorSer(id));
		return "org/doctor/edit";
	}
	
	/**
	 * 修改医生详情(模块:医生)
	 * 
	 * @param BaseDoctor baseDoctor
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/updateBaseDoctor")
	@ResponseBody
	public AjaxRes updateBaseDoctor(AjaxRes ajaxRes,BaseDoctor baseDoctor){
		try {
			this.doctorPharmacistService.updateBaseDoctorSer(baseDoctor);
			ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 组织机构树
	 */
	@RequestMapping("/orgtree")
	@ResponseBody
	public Tree<MenuDO> queryorgtree(){
		Tree<MenuDO> queryorgtrees = doctorPharmacistService.queryorgtreeSer();
	    return queryorgtrees;
	}
	
	/**
	 * 组织机构树(编辑)
	 */
	@GetMapping("/tree/{orgId}")
	@ResponseBody
	Tree<MenuDO> tree(@PathVariable("orgId") Long orgId) {
		Tree<MenuDO> tree = doctorPharmacistService.getTree(orgId);
		return tree;
	}
	/**
	 * 医生是否重复(新增)
	 * 
	 * @param Map<String,Object> map
	 *         
	 * @return boolean
	 */
	@PostMapping("/doctorValidate")
	@ResponseBody
	public boolean validate(@RequestParam Map<String,Object> map){
		return !doctorPharmacistService.doctorValidateSer(map);
	}
	
	/**
	 * 医生是否重复(修改)
	 * 
	 * @param Map<String,Object> map
	 *         
	 * @return boolean
	 */
	@PostMapping("/updateDoctorValidate")
	@ResponseBody
	public boolean updateDoctorValidate(String parameter){
		return !doctorPharmacistService.updateDoctorValidateSer(parameter);
	}
	
	/**
	 * 药生是否重复(新增)
	 * 
	 * @param Map<String,Object> map
	 *         
	 * @return boolean
	 */
	@PostMapping("/pharmacistValidate")
	@ResponseBody
	public boolean pharmacistValidate(@RequestParam Map<String,Object> map){
		return !doctorPharmacistService.pharmacistValidateSer(map);
	}
	
	/**
	 * 药师是否重复(修改)
	 * 
	 * @param Map<String,Object> map
	 *         
	 * @return boolean
	 */
	@PostMapping("/updatePharmacistValidate")
	@ResponseBody
	public boolean updatePharmacistValidate(String parameter){
		return !doctorPharmacistService.updatePharmacistValidateSer(parameter);
	}
}
